<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>我的任务</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
        <div>
            <div id="pageInTab" class="pageInTab">
                <div tabid="tabA" title="待办事宜" lselected="true">
                	<div class="searchArea">
					    <form id="searchBar">
					        <div class="fieldset1 clearFix">
					            <div class="fieldBox">
					                <div class="label" style="width: 60px;">流程名称</div>
					                <div class="field">
					                    <input name="flowDefNm" id="flowDefNm" type="text" class="ui-textbox" value="">
					                </div>
					            </div>
					            <div class="fieldBox">
					                <div class="label" style="width: 60px;">处理节点</div>
					                <div class="field">
					                    <input name="taskNm" id="taskNm" type="text" class="ui-textbox" value="">
					                </div>
					            </div>
					            
					            <div class="fieldBox">
					                <div class="label" style="width: 60px;">承租人</div>
					                <div class="field">
					                    <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
					                </div>
					            </div>
					            <!-- <div class="fieldBox">
					                <div class="label" style="width: 60px;">项目名称</div>
					                <div class="field">
					                    <input name="prjNm" id="prjNm" type="text" class="ui-textbox" value="">
					                </div>
					            </div> -->
					            
					            <!--  <div class="fieldBox">
					                <div class="label" style="width: 60px;">事业部</div>
					                <div class="field">
					                    <select name="orgCd1" id="orgCd1">
					                       <option value="" seleted>请选择</option>
					                       <c:forEach items="${orgListList }" var="orgCd">
					                        	<option value="${orgCd.key }">${orgCd.value }</option>
					                        </c:forEach>
					                    </select>
					                </div>
					            </div>-->
					            
					            <div class="fieldBox col_50">
				                    <div class="label" style="width: 60px;">组织机构</div>
				                    <div class="field">
				                        <input name=searchOrgCd id="searchOrgCd" type="text" value="" placeholder="请选择" ltype="combobox">
				                    </div>
				                </div>
					            
					            <div class="fieldBox">
					                <div class="label" style="width: 60px;">业务模式</div>
					                <div class="field">
					                    <select name="businessType" id="businessType" >
					                       <option value="" seleted>请选择</option>
					                       <c:forEach items="${businessTypeList }" var="item">
					                        	<option value="${item.key }">${item.value }</option>
					                       </c:forEach>
					                    </select>
					                </div>
					            </div>
					            
								<div class="fieldBox">
					                <div class="label" style="width: 60px;">任务源</div>
					                <div class="field">
					                    <select name="bizResCd" id="bizResCd">
					                       <option value="" seleted>请选择</option>
					                       <c:forEach items="${businessSourceList }" var="item">
					                        	<option value="${item.key }">${item.value }</option>
					                       </c:forEach>
					                    </select>
					                </div>
					            </div>
								    
								<div class="fieldBox">
					                <div class="label" style="width: 60px;">发起人</div>
					                <div class="field">
					                    <input name="initiator" id="initiator" type="text" class="ui-textbox" value="">
					                </div>
					            </div>
					            
					            <div class="fieldBox">
					                <div class="label" style="width: 60px;">新处理人</div>
					                <div class="field">
					                    <input name="assigneeNm" id="assigneeId" type="text" class="ui-textbox" value="">
					                </div>
					            </div>
					            
								<div class="fieldBox">
					                <div class="label" style="width: 60px;">原处理人</div>
					                <div class="field">
					                    <input name="ownerNm" id="ownerId" type="text" class="ui-textbox" value="">
					                </div>
					            </div>					            
					            
					            <div class="fieldBox">
					                <div class="label" style="width: 60px;">流程编号</div>
					                <div class="field">
					                    <input name="procNo" id="procNo" type="text" class="ui-textbox" value="">
					                </div>
					            </div>  
					            
 								<div class="fieldBox">
					                <div class="label" style="width: 60px;">关键字</div>
					                <div class="field">
					                    <input name="viKey" id="viKey" type="text" class="ui-textbox" value="">
					                </div>
					            </div>
								<!--
								<div class="fieldBox">
									<div class="label" style="width: 60px;">关键字1</div>
									<div class="field">
										<input name="viKey1" id="viKey1" type="text" class="ui-textbox" value="">
									</div>
								</div>
								-->
								<!-- 登录用户角色为权证人员的显示"快递单号" -->
					            <c:if test="${warrantFlag == 1 }">
						            <div class="fieldBox">
						                <div class="label" style="width: 60px;">快递单号</div>
						                <div class="field">
						                    <input name="sendNum" id="sendNum" type="text" class="ui-textbox" value="">
						                </div>
						            </div>
					            </c:if>
								
					            <div class="clearFix"></div>
					            <div class="btnsBox">
					               <span id="searchBtn" class="sq-button sq-button-round">查询</span>
					               <span onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
					               <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
					               <input name="isSignNm" id="isSignId" type="text" style="display: none;" value="0"/>
					               <input name="warrantFlag" id="warrantFlag" type="text" style="display: none;" value="${warrantFlag}"/>
					            </div>
					        </div>
					    </form>
					</div>
                    <div id="ligergridDB" class="sq-grid"></div>
                </div>
                <div tabid="tabB" title="挂起事宜">
                     <iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
                </div>
                <!-- <div tabid="tabC" title="完结事宜">
                    <iframe frameborder="0" name="tabC" id="tabC" src=""></iframe>
                </div> -->
            </div>
        </div>
    </div>

<script type="text/javascript">
	var gridDB = null;
	var pageInApp={}; // to 下一级子窗口 接口
    var pageInTab=null;
    var loadedTabs=[]
	$(function () {
		$("#exeFlowId").hide();
		$("#privateTaskId").hide();
		initTab();
		initGridDB();//初始化待办列表
		initOrgTree();//注意要放在ligerForm之前加载
	    $("#searchBar").ligerForm();
	    $("#searchBtn").click(function(event) {
	    	reloadGrid();
	    });
	});
    
    //重新加载GRID
    function reloadGrid(){
    	var form = new liger.get("searchBar");
        var data = form.getData();
        //组织架构显示名称
        /* if(searchOrgTree.treeManager.getSelected()){
       	 var orgDispNm = searchOrgTree.treeManager.getSelected().data['orgDispNm'];
	         if(orgDispNm){
	        	 data["orgDispNm"] = orgDispNm;
	         }
        } */
        if(searchOrgTree.treeManager.getSelected()){
          	 var orgCd = searchOrgTree.treeManager.getSelected().data['orgCd'];
   	         if(orgCd){
   	        	 data["searchOrgCd"] = orgCd;
   	         }
        }
        //业务类型要名字 businessType
        var _businessType = $("#businessType").val();
        //alert(_businessType);
        var _businessTypeName = $("select[name=businessType] option[value='"+_businessType+"']").text();
        if(_businessTypeName == "请选择"){
        	_businessTypeName = "";
        }
        data["businessType"] = _businessTypeName;//用中文作为查询条件
        
        for (name in data){
	        gridDB.setParm(name,data[name]);
	    };
	    gridDB.reload();
    }
    
    //初始化查询条件中的下拉树
    var searchOrgTree;
    function initOrgTree(){
    	 searchOrgTree = $("#searchOrgCd").ligerComboBox({
             selectBoxWidth: 240,
             selectBoxHeight: 150,
             treeLeafOnly: false, //限制只能选叶节点，父节点不能点击
             tree: {
                 ajaxType: 'get',
                 textFieldName:'text',
                 checkbox: false,
                 parentIcon: "none",
                 childIcon: "none"
             }
         });
    	 var _url = '<%=path%>/system/sysOrg/searchOrgTree.do';
    	 AjaxUtils.ajaxGet(_url, {}, function(msg){
    		if(msg.success == 1){
  				searchOrgTree.treeManager.setData(msg.data);
  				searchOrgTree.clear();
  			}else{
  				UIUtils.alertError(msg.info);
  			}
    	 },false);
    }
    
  	//设置代办人,根据当前人指定给谁处理在指定时间内的事情
	function setAgent(){
		$.ligerDialog.SQopen({
            width: 850,
            height:400,
            title : '设置代办人',
            url:'<%=path%>/flow/flow/toSetAgentUsrPage.do'
        });
	}
    
    //初始化待办列表
    function initGridDB(){
    	$("#ligergridDB").ligerGrid({
	    	url: '<%=path%>/flow/flow/initMyTaskDBList.do',
	    	method : 'get',
	        columns: [
	            { display: '任务源', name: 'taskTypeNm',  width: 100, enabledSort:false},
	            { display: '流程名称', name: 'processDefinitionNm',  minWidth: 200, enabledSort:false},
	            { display: '流程编号', name: 'procNo',  width: 120, enabledSort:false},
	            { display: '处理节点', name: 'name',  width: 100, enabledSort:false},
	            { display: '承租人', name: 'cstNm', minWidth: 120 , enabledSort:false,
	            	render: function (rowdata, rowindex, value){
	        			return UIUtils.showColumnTip(value);
	            	}
	            },
	            /* { display: '关键字', name: 'taskDesc', minWidth: 140 , enabledSort:false}, */
	            /* 
	            { display: '项目名称', name: '', minWidth: 140 , enabledSort:false},
	            { display: '事业部', name: '', minWidth: 140 , enabledSort:false}, */
	            /* { display: '业务类型', name: 'businessTypeNm', minWidth: 120 , enabledSort:false}, */
	            { display: '发起人', name: 'initiatorNm', width: 60,align:'left' , enabledSort:false},
	            { display: '处理状态', name: 'statusNm', minWidth: 100 , enabledSort:false},
	            { display: '新处理人', name: 'assigneeNm', minWidth: 120 , enabledSort:false,
	            	render: function (rowdata, rowindex, value){
	        			return UIUtils.showColumnTip(value);
	            	}
				},
	            { display: '原处理人', name: 'ownerNm', minWidth: 80 , enabledSort:false},
	            { display: '组织架构', name: 'orgNm', minWidth: 140 , enabledSort:false},
	            { display: '任务创建时间', name: 'startTime', minWidth: 140 , render:renderDate, enabledSort:false},
	            { display: '当前耗时', name: 'durationStr', minWidth: 140 , enabledSort:false},
	            getOperColumn()
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-30,
	        checkbox:true,
	        rownumbers:true
	    });
	    gridDB = liger.get("ligergridDB");
	    gridDB.setHeight(100);
	    gridDB.options.isSingleCheck=true;
    }
    
    //获取最后操作列
    function getOperColumn(){
    	return {
            display: '操作',
            width: 160,
            align:'left',
            render: function (rowdata, rowindex, value) {
            	//如果assignee为空则显示签收按钮, 如果组内任务标识grpShr为true需要显示处理按钮
            	var other= "";
            	if($.trim(rowdata.groupShare) == "true"){
            		if($.trim(rowdata.assignee) == ""){
            			 other+='<a id="grid_row_private_btn_id" class="sq-button-hasicon" href="javascript:;" onclick="privateRow(';
    	        		 other+="'"+rowindex+"'";
    	                 other+=")\"><i class=\"sqBtnIco_43\"></i>"+LogUtils.LOG_FLOW_PRIVATE_ROW+"</a>";
            		}
	                other+='<a id="grid_row_exe_btn_id" class="sq-button-hasicon" href="javascript:;" onclick="exeRow(';
	        		other+="'"+rowindex+"'";
	                other+=")\"><i class=\"sqBtnIco_46\"></i>"+LogUtils.LOG_FLOW_EXE_ROW+"</a>";
            	}else if($.trim(rowdata.assignee) == ""){
	        		 other+='<a id="grid_row_private_btn_id" class="sq-button-hasicon" href="javascript:;" onclick="privateRow(';
	        		 other+="'"+rowindex+"'";
	                 other+=")\"><i class=\"sqBtnIco_43\"></i>"+LogUtils.LOG_FLOW_PRIVATE_ROW+"</a>";
	        	}else{
	        		 other+='<a id="grid_row_exe_btn_id" class="sq-button-hasicon" href="javascript:;" onclick="exeRow(';
	        		 other+="'"+rowindex+"'";
	                 other+=")\"><i class=\"sqBtnIco_46\"></i>"+LogUtils.LOG_FLOW_EXE_ROW+"</a>";
	        	}
                return other;
            }
        };
    }
    
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}
	
	//处理流程
	function exeRow(_index){
		var rowdata = gridDB.rows[_index];
    	var wait_dialog = UIUtils.alertWaiting(LogUtils.LOG_CMM_DATA_LOADING, function(){});
		//非业务参数
		var _name = rowdata.name;
		var _id = rowdata.id;
		//业务参数
		var _processDefinitionId = rowdata.processDefinitionId;//流程定义ID
		var _processInstanceId = rowdata.processInstanceId;//流程实例ID
		var _processInstanceCode = rowdata.procNo;//流程实例编号
		var _taskId = rowdata.taskId;//任务ID
		var _assignable = rowdata.assignable;//是否可分配按钮的标识 true fasle
		var _formUrl = rowdata.formUrl;//表单地址
		var _flowList = rowdata.sequenceFlowVOList;//任务分出连线
		var _processDefinitionKey = rowdata.processDefinitionKey;//流程定义Key
		var _taskDefKey = rowdata.taskDefKey;//任务定义Key
		var _businessKey = rowdata.businessKey;//业务数据ID
		var _taskType = rowdata.taskType;//任务类型标识,后面区分按钮的显示与否
		var _status = rowdata.status;//任务状态
		var _assignee = rowdata.assignee;//任务受理人
		var _businessType = rowdata.businessType;//业务类型
		var _originTaskId = rowdata.originTaskId;//原始任务ID
		var _beanName = rowdata.beanName;//业务Bean
		var _taskDefKeyNm = rowdata.name;
		var _groupShare = rowdata.groupShare;//签收后组内是否可见
		var procDefName = rowdata.processDefinitionNm;//流程定义名称
		var isFormAuth = rowdata.isFormAuth;//是否有节点表单权限
		var preTaskId = rowdata.preTaskId;//上一个节点任务ID,多个已逗号分割
		
		var params = "processDefinitionId="+_processDefinitionId+
			"&processInstanceId="+_processInstanceId+
			"&taskId="+_taskId+
			"&businessKey="+_businessKey+
			"&assignable="+_assignable+
			"&formUrl="+_formUrl+
			"&taskType="+_taskType+
			"&processDefinitionKey="+_processDefinitionKey+
			"&taskDefKey="+_taskDefKey+
			"&taskDefKeyNm="+_taskDefKeyNm+
			"&status="+_status+
			"&assignee="+_assignee+
			"&businessType="+_businessType+
			"&originTaskId="+_originTaskId+
			"&beanName="+_beanName+
			"&flowList="+JSON.stringify(_flowList)+
			"&grpShr="+_groupShare+
			"&procNo="+_processInstanceCode+
			"&isSign="+$("#isSignId").val()+
			"&procNm="+procDefName+
			"&isFormAuth="+isFormAuth+
			"&preTaskId="+preTaskId;
		
		//处理流程关闭后回调
		var callback = function() {
			reloadGrid();
	    };
	    Add_navTab('tab_flow_exe_'+_taskId,_name,'<%=path%>/flow/flow/toExeFlowPage.do?' + params, callback);
	    wait_dialog.close();
	}
	
	//签收
   	function privateRow(_index){
   			var rowdata = gridDB.rows[_index];
	    	//业务参数
			var _taskId = rowdata.taskId;//任务ID
			var _processDefinitionKey = rowdata.processDefinitionKey;//流程定义Key
			var _taskDefKey = rowdata.taskDefKey;//任务定义Key
			var _processDefinitionId = rowdata.processDefinitionId;//流程定义ID
			var _businessKey = rowdata.businessKey;//业务数据ID
			var _processInstanceId = rowdata.processInstanceId;//流程实例ID
	     	var _attchmnt = "[]";//附件的集合
	     	var _taskOpinion = "签收";//
	     	var _businessType = rowdata.businessType;//业务类型
			var _businessBean=rowdata.beanName;

		var parms = {
	    			taskId:_taskId,
	    			processDefinitionKey:_processDefinitionKey,
	    			taskDefKey:_taskDefKey,
	    			processDefinitionId:_processDefinitionId,
	     			taskId:_taskId,
	     			businessKey:_businessKey,
	     			processInstanceId:_processInstanceId,
	     			attchmnt:_attchmnt,
	     			taskOpinion:_taskOpinion,
	     			businessType:_businessType,
	     			isSign:1,
					businessBean:_businessBean

		}
	    	
	    	var _url = '<%=path%>/flow/flow/modifyFlowPrivate.do';
	    	AjaxUtils.ajaxPost(_url, parms, function(msg){
	    		if(msg.success == 1){
	   				 UIUtils.alertSuccess(msg.info);
	   				 //特殊处理,先获取到当前签收人,然后把当前签收人设置为选中行的受理人,而且这里签收后必须要设置。
	   				 var rowdata = gridDB.rows[_index];
	   				 gridDB.updateRow(rowdata,{
	   					assignee: msg.data,
	   				 });
	   				 $("#isSignId").val(1);//签署标识,传递个附加页面使用
	   				 exeRow(_index);//执行流程
	   			}else{
	   				 UIUtils.alertError(msg.info);
	   			}
	    	},true);
    };
	
	function clearBtn(){
		$("#resetBtn").click();  //重置 input-text
		var form = liger.get("searchBar");
        $("#orgCd").val("");
        form.setData({  //重置select等特殊表单
            //"orgCd": " ",
            "businessType":" ",
            "bizResCd":" "
        });
        searchOrgTree.clear();
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	
	
	//初始化Tab页
    function initTab(){

        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onAfterSelectTabItem: function(tabid) {
            	currTab = tabid;//赋值是哪个Tab页面
                if (loadedTabs.indexOf(tabid)<0) {
                    loadedTabs.push(tabid);
                    switch (tabid){
                        case "tabB":
                            pageInTab.setTabItemSrc(tabid, "<%=path%>/flow/flow/toMyTaskGQPage.do");
                            break;
                        //case "tabC":
                          //  pageInTab.setTabItemSrc(tabid, "<%=path%>/flow/flow/toMyTaskWJPage.do");
                            //break;
                    }
                };
                SetIframe_height();
            }
        });

        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });
    }
</script>

</body>
</html>